using Microsoft.OpenApi.Models;

namespace Cordyceps.Demo.HttpApi.Host;

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);
        // 添加控制器并从 HttpApi 程序集发现控制器
        builder.Services.AddControllers();
        //.AddApplicationPart(typeof(WeatherForecastController).Assembly);

        // 添加 Swagger 服务
        builder.Services.AddEndpointsApiExplorer();
        builder.Services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo
            {
                Title = "My API",
                Version = "v1"
            });
        });


        var app = builder.Build();

        app.UseHttpsRedirection();

        app.UseAuthorization();

        // 开发环境启用 Swagger 中间件
        if (app.Environment.IsDevelopment())
        {
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Cordyceps.Demo.HttpApi V1");
                c.RoutePrefix = "swagger"; // 可设为空 "" 来让根路径完全由重定向控制
            });
        }

        app.MapControllers();

        app.Run();
    }
}